package com.xzy.simple;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

/**
 * {@link UserEvent} 事件发布器
 *
 * @author xzy.xiao
 * @date 2022/10/8  19:09
 */
public class UserEventPublisher {
    private static final Logger logger = LoggerFactory.getLogger(UserEventPublisher.class);

    public static void sendInsertEvent(ApplicationContext applicationContext) {
        UserEvent userEvent = new UserEvent(UserEvent.EventType.INSERT, new User(1000L, "张三"));
        logger.info("发布事件：{}", userEvent);
        applicationContext.publishEvent(userEvent);
    }

    public static void sendDeleteEvent(ApplicationContext applicationContext) {
        UserEvent userEvent = new UserEvent(UserEvent.EventType.DELETE, new User(1000L, "张三"));
        logger.info("发布事件：{}", userEvent);
        applicationContext.publishEvent(userEvent);
    }

    public static void sendUpdateEvent(ApplicationContext applicationContext) {
        UserEvent userEvent = new UserEvent(UserEvent.EventType.UPDATE, new User(1000L, "张三"));
        logger.info("发布事件：{}", userEvent);
        applicationContext.publishEvent(userEvent);
    }
}
